package com.quwan.manager.controller;

import com.quwan.common.BaseController;
import com.quwan.common.result.ApiResult;
import com.quwan.common.result.PageResult;
import com.quwan.entity.TMemberReport;
import com.quwan.manager.service.MemberReportService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author laozhang
 * @date 2021/11/18 9:47
 */
@Api(tags = "后台举报列表管理接口")
@RestController
@RequiredArgsConstructor
@RequestMapping("mgr/memberReport")
public class MemberReportController extends BaseController {

    private final MemberReportService memberReportService;

    @ApiOperation("举报列表分页")
    @PostMapping("reportListPage")
    public ApiResult<PageResult<TMemberReport>> reportListPage(@RequestParam(defaultValue = "1") int page,
                                                               @RequestParam(defaultValue = "10") int size,
                                                               @ApiParam("用户名") @RequestParam(required = false) String name,
                                                               @ApiParam("举报人Id") @RequestParam(required = false) String sourceId,
                                                               @ApiParam("被举报人Id") @RequestParam(required = false) String targetId,
                                                               @ApiParam("状态0待处理 1已禁用 2不处理") @RequestParam(required = false) Integer status,
                                                               @ApiParam("开始时间 格式：yyyy-MM-dd") @RequestParam(required = false) String beginTime,
                                                               @ApiParam("结束时间 格式：yyyy-MM-dd") @RequestParam(required = false) String endTime) {
        PageResult<TMemberReport> res = memberReportService.getMemberReportListPage(page,size,status,name,beginTime,endTime,sourceId, targetId);
        return ApiResult.success(res);
    }

    @ApiOperation("举报列表")
    @PostMapping("reportList")
    public ApiResult<List<TMemberReport>> reportList(@ApiParam("用户名") @RequestParam(required = false) String name,
                                               @ApiParam("状态0待处理 1已禁用 2不处理") @RequestParam(required = false) Integer status,
                                               @ApiParam("开始时间 格式：yyyy-MM-dd") @RequestParam(required = false) String beginTime,
                                               @ApiParam("结束时间 格式：yyyy-MM-dd") @RequestParam(required = false) String endTime) {
        List<TMemberReport> res = memberReportService.getMemberReportList(status,name,beginTime,endTime);
        return ApiResult.success(res);
    }

    @ApiOperation("举报列表——处理")
    @PostMapping("reportUpdate")
    public ApiResult<String> reportUpdate(@ApiParam("主键id") @RequestParam(required = true) Long id,
                                       @ApiParam("被举报人id") @RequestParam(required = true) Long targetId,
                                       @ApiParam("状态0待处理 1已禁用 2不处理") @RequestParam(required = true) Integer status) {
        boolean b = memberReportService.updateMemberReportStatus(id,targetId,status);
        if(b)
           return ApiResult.success();
        else
            return ApiResult.failed();
    }

}
